package com.fairytask.ui
{
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.text.Text;
	import com.fairytask.managers.ViewManage;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.ui.base.FrameUI;
	
	import flash.events.MouseEvent;
	
	/**
	 *事件系统提示面板框 
	 * @author pangj
	 * 
	 */
	public class PanelUI extends FrameUI
	{
		private static const EVENT_HUANGCHENG :int = 1;  //皇城寻路
		private static const EVENT_WILD       :int = 2;  //野外寻路
		private static const EVENT_SHOW_PANEL :int = 4;  //显示面板
		
		private static var _self:PanelUI;
		
		public var describe   :Text;  //描述文字
		public var closeBtn   :Button;//关闭按钮
		
		public function PanelUI(popUI:Boolean=true)
		{
			super(popUI);
			initEvent();
		}
		private function initEvent():void
		{
			closeBtn.addEventListener(MouseEvent.CLICK,onClose);
		}
		public static function getInstance():PanelUI
		{
			if(_self==null)
			{
				_self=new PanelUI();
			}
			return _self;
		}
		
		override public function show(space:String=BACKLAYER, onshow:Function=null):void
		{
			super.show(space,onshow);
			ViewManage.maskEnable	=	false;
		}
		/**
		 * 设置描述文字
		 * 
		 */
		public function set Describe(val:String):void
		{
			show();
			//trace("string:"+val);
			describe.htmlStr = val;
			describe.setFilter();
			describe.addLinkClickHandel(onClick);
		}
		/**
		 * 点击文字,显示链接窗口
		 * 
		 */
		public function onClick(val:String):void
		{	
			//trace("click:"+val);
			var arr:Array = val.split(",");
			if(int(arr[0]) == EVENT_SHOW_PANEL)
			{
				ViewManage.retrieveUIByID(arr[1]).show();
				onClose(null);
				return;
			}
			var npcInfo:Object = StaticIni.getIniObj(arr[1]);
			dispatchEvent(new MouseEvent(MouseEvent.CLICK));
			if(int(arr[0]) == EVENT_HUANGCHENG)
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_MOVE_TO_NPC,int(arr[1]));
			}
			else
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_MOVE_OTHER_SCENE,int(arr[1]));
			}
			onClose(null);
		}
		/**
		 * 关闭面板
		 * 
		 */
		private function onClose(evt:MouseEvent):void
		{
			if(null != this.parent)
			{
				this.parent.removeChild(this);
			}
			getInstance().hide();
		}
	}
}